package chapter17;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/24 15:22
 */
public class TimerFixedDelay {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new LongTimeTask(), 0, 10);
        timer.schedule(new FixRateTask(), 100, 1000);
    }

    static class LongTimeTask extends TimerTask {

        @Override
        public void run() {
            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("longTimeTask");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    static class FixRateTask extends TimerTask {
        @Override
        public void run() {
            System.out.println("fixedrate task");
        }
    }

}
